<template>
  <div>
    <van-nav-bar title="京东注册发送验证码" left-text="返回" left-arrow @click-left="onClickLeft" />

    <van-cell-group inset>
      <van-field v-model="checktel" name="checktel" label="手机号" placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]" />
      <van-field v-model="msg" name="checktel" label="验证码" placeholder="验证码"
        :rules="[{ required: true, message: '请填写验证码' }]">
        <template #button>
          <van-button type="primary" size="mini" @click="sendMsg">发送验证码</van-button>
        </template>
      </van-field>
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit" @click="goSendpass">
        提交
      </van-button>
    </div>
  </div>
</template>

<script>
import { doSendmsgcode, doCheckcode } from '@/apis/wode';
export default {
  data() {
    return {
      checktel: '',
      msg: ''
    }
  },
  methods: {
    onClickLeft() {
      history.back()
    },
    goSendpass() {

    },
    sendMsg() {
      doSendmsgcode({ tel: this.checktel }).then(res => {
        if (res.data.code != 200) {
          return showToast("发送验证码失败")
        } else {
          console.log(res);
          this.msg = res.data.data
        }
      })
    },
    goSendpass() {
      doCheckcode({ tel: this.checktel, telcode: this.msg }).then(res => {
        console.log(res);
        if (res.data.code == 10007) {
          return showToast("验证码错误")
        }else{
          this.$router.push('/register/sendpass')
        }
      })
    }
  },
  created() {
    this.checktel = localStorage.getItem("tel")
  }
}
</script>

<style lang="less" scoped></style>